#pragma once
#include <QPixmap>
#include <QWidget>
#include <QPainter>
#include <QMouseEvent>

class Canvas : public QWidget {
public:
    Canvas(QWidget *parent);

    void paintEvent(QPaintEvent *) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

    void clear();
    void setWidth(int w) { pen.setWidth(w); }
    QImage getImage() {return buffer.toImage();}

private:
    QPen pen;
    bool onDrawing;
    QPixmap buffer;
    QPainter painter, temp;
    QPoint prev, current;
};